<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page import="java.util.*, java.io.*" %>

<head>
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
	<title>Students Calendars</title>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<link href="style/default.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>	
	<hr />
	<div id="logo">
  	<h1><a href="#">Calendars </a></h1>
  	<p>for you :)</p>
	</div>

	<div id="menu">
  		<ul>
  		<%String login = (String)request.getSession().getAttribute("username");
  		  Integer op = 1;
  		  if (request.getParameter("op") != null){
  			op = new Integer(request.getParameter("op"));
  		  }
  		  if (login != null) {
  		 %>
    		<li class="Clicklink" id="1">Home</li>
    	
    	<%// only admin see users
    	  String admin = (String)request.getSession().getAttribute("administrator");
		  if (admin.equals("true")) {
  		 %>
    		<li class="Clicklink" id="2">Users</li>
    	<% } %>
    		<li class="Clicklink" id="3">Courses</li>
   			<li class="Clicklink" id="4">Profile</li>
  			<li class="Clicklink" id="5">About</li>
  			<li class="Clicklink" id="6">Log-Out</li>
  		<% 	}
 		 %>
 		</ul>
	</div>
	
<script type="text/javascript">                                         
	$(document).ready(function()
		{	
			$('.Clicklink').removeClass("Clicklinkactive");
			$('#<%=op%>').addClass("Clicklinkactive");
			$('.Clicklink').click(function()
				{
					if ($(this).attr("id") == "6"){
						window.location=("/Calendars/Login");
						return;
					}
					window.location=("/Calendars/index.jsp?op=" + $(this).attr("id"));
				});
			$('.Clicklink').hover(function() {$(this).css('cursor','pointer');}, function() { $(this).css('cursor','auto');});
		});
</script>

	
	<div id="page">
<% if (login == null) {                                       %>
			<%@ include file="/login.jsp" %>
<%    }
	  else{
		  switch (op) {
		  	  	case 1:                                  %>
		  	  	<%@ include file="/Web/home.jsp" %>
<%     						break;
		 		case 4:                               %>
		  		<%@ include file="/Web/profile.jsp" %>
<% 	            break;
		  }

  	  }
  		%>
  	</div>
  	<div style="clear: both;">&nbsp;</div>
	<div id="footer">
  		<p id="legal">&copy;All Rights Reserved Ayoub And Adi and some guides from the wide web :P </p>
  		<p id="links"> <a href="#">Terms</a> | <a href="#">Sue us</a>  </p>
	</div>

<%  //incase login faild show an alert.
	String LastResultFailed = (String)request.getSession().getAttribute("LastResultFailed");
	if (LastResultFailed != null) { %>
		<script type="text/javascript"> 
		alert("Login Failed!\n"+
		      "Please check your username and password"); 
		</script>
<% 		request.getSession().removeAttribute("LastResultFailed");
		}%>
		
<% //incase registration faild:
	String usernameExist = (String)request.getSession().getAttribute("usernameExist");
	if (usernameExist != null) { %>
		<script type="text/javascript"> 
			$('#page').load("registration.jsp");
			alert("Registration Failed!\n"  +
				  "Username already exist!\n" +
				  "Please choose another Username"); 
		</script>
<% 	request.getSession().removeAttribute("usernameExist");
		} else {
			String wrongCode = (String)request.getSession().getAttribute("wrongCode");
			if (wrongCode != null) { %>
				<script type="text/javascript"> 
					$('#page').load("registration.jsp");
					alert("Registration Failed!\n"  +
						  "wrong administrator code!");
					
				</script>
 <%     	request.getSession().removeAttribute("wrongCode");
			}
		} %>

</body>

</html>